#include "settingscene.h"
#include "item/imageitem.h"
#include "recource.h"
#include "sound/GameSounds.h"
#include <QLocale>

SettingScene::SettingScene(QObject *parent) :
    QGraphicsScene(parent)
{
    setSceneRect(0.0, 0.0, 360.0, 640.0);
    initItem();
}

void SettingScene::initItem()
{
    switch(Recource::m_iLanguage)
    {
    case QLocale::Chinese:
    {
        m_bgItem = new ImageItem(*Recource::m_aboutBgCnImage,
                                 QRect(QPoint(0,0),Recource::m_aboutBgCnImage->size()));
        m_backItem = new ImageItem(*Recource::m_backbtnImage,
                                    QRect(QPoint(0,0),Recource::m_backbtnImage->size()));
        m_backItem->setPos(111.0,576.0);
    }
        break;
//    case QLocale::HongKong:
    case 255:
    {
        m_bgItem = new ImageItem(*Recource::m_aboutBgHkImage,
                                 QRect(QPoint(0,0),Recource::m_aboutBgHkImage->size()));
        m_backItem = new ImageItem(*Recource::m_backbtnImage,
                                    QRect(QPoint(0,0),Recource::m_backbtnImage->size()));
        m_backItem->setPos(111.0,576.0);
    }
        break;
    default:
    {
        m_bgItem = new ImageItem(*Recource::m_aboutBgEnImage,
                                 QRect(QPoint(0,0),Recource::m_aboutBgEnImage->size()));
        m_backItem = new ImageItem(*Recource::m_backbtnEnImage,
                                    QRect(QPoint(0,0),Recource::m_backbtnEnImage->size()));
        m_backItem->setPos(108.0,569.0);
    }
        break;
    }

    m_bgItem->setPos(0.0,0.0);
    m_bgItem->setZValue(0.0);
    addItem(m_bgItem);

    m_backItem->setZValue(1.0);
    m_backItem->setVisible(false);
    addItem(m_backItem);
}

void SettingScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    if(m_backItem->isUnderMouse())
    {
        m_backItem->setVisible(true);

        if(Recource::m_bPlaySound)
        {
            Recource::m_gamesound->play(0);
        }
    }
}

void SettingScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
   m_backItem->setVisible(false);
   if(m_backItem->isUnderMouse())
   {
       Recource::SetMain();
   }
}
